package socket;

import java.io.*;
import java.net.Socket;
import java.util.Date;

public class Client {

    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("localhost", 8051);

        OutputStream os = socket.getOutputStream();
        PrintWriter writer = new PrintWriter(os);
        writer.print("服务端你好" + new Date().toLocaleString());
        writer.flush();
        socket.shutdownOutput();

        InputStream is = socket.getInputStream();
        InputStreamReader reader = new InputStreamReader(is);
        BufferedReader buffer = new BufferedReader(reader);
        String temp;
        String info = "";
        while ((temp = buffer.readLine()) != null) {
            info += temp;
            System.out.println("客户端接收到消息:" + info);
        }

        buffer.close();
        reader.close();
        is.close();
        writer.close();
        os.close();
        socket.close();
    }
}
